<html>
	<?
	include 'web/header.phtml';
	?>
<style>
	.ProductTable table {
		font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
		font-size: 12px;
		width: 700px;
		text-align: left;
		border-collapse: collapse;
		margin: 20px;
	}
	.ProductTable thead {
		display: table-header-group;
		vertical-align: middle;
		border-color: inherit;
	}
	.ProductTable th {
		font-size: 13px;
		font-weight: normal;
		background: #B9C9FE;
		border-bottom: 1px solid white;
		color: #039;
		padding: 8px;
	}
	.ProductTable td {
		background: #E8EDFF;
		border-bottom: 1px solid white;
		color: #669;
		border-top: 1px solid transparent;
		padding: 8px;
	}
	.ProductTable tr:hover td {
		background: #D0DAFD;
		color: #339;
	}
	</style>
	<script type="text/javascript">
		function selectProduct(ProductID) {
			$.getJSON('admin.php', {
			view : "product",
			do : "select",
			ProductID : ProductID
			}, function(data) {
				$("#Name").val(data.Name);
				$("#Price").val(data.Price);
				$("#Quantity").val(data.Quantity);
				$("#Category").val(data.Category);
				$("#Description").val(data.Description);

			});

		}

		function addtocart(proid) {
			$.ajax({
			type : "POST",
			url : "cart.php",
			data: { do: "add", id: proid }, success : function(html) {
				alert(html);
			}
		});

		}

		function addProduct() {
			$.ajax({
			type : "POST",
			url : "admin.php?view=product",
			data: {
			do: "add",
			Name: $("#Name").val(),
			Price: $("#Price").val(),
			Quantity: $("#Quantity").val(),
			Category: $("#Category").val(),
			ImageName: $("#ImageName").val(),
			Description: $("#Description").val(),
			}, success : function(html) {
				alert(html);
			}
		});

		}
		function deleteProduct(ProductID) {
			if (confirm('Are you sure want to delete product ' + ProductID + '?')) {
				$.ajax({
				type : "POST",
				url : "admin.php?view=product",
				data: { do: "delete", ProductID: ProductID }, success : function(html) {
					alert(html);
				}
			});
			}
			else
			alert('Undeleted')
		}
	</script>

	<body>

		<?
		include 'web/body.header.phtml';
		include 'web/body.menu.phtml';
		?>

		<div id="page">

			<?
			include 'web/body.banner.phtml';
			?>
			<?
			include 'view/listCategory.php';
			?>
			<div id="content">
				<div class="box" id="box3">
					<h2 class="title1"><?=$MSS ?></h2>
					<div class="entry">

						<div style="clear: both; margin-bottom: 20px;"></div>
						<div class="ProductTable">	
						<!-- start content -- -->	
						<?echo $PageLink?>					
						<table>
							
							<?php
							if (count($products) > 0) {
								echo "<thead>
								<tr>
									<th>Name</th><th>Category</th><th>Quantity</th><th>Price</th><th>Action</th>
								</tr>
							</thead>";
								foreach ($products as $product) {
									echo "<tr>
<td>$product[Name]</td>
<td>$product[Category]</td>
<td>$product[Quantity]</td>
<td>$product[Price]</td>
<td><input type='button'value='Select' onclick=selectProduct($product[ProductID]) style='width:60px'/>
<button onclick=deleteProduct($product[ProductID])>Delete</button></td>
</tr>";
								}
							}
							?>
						</table>

						<form name="addproduct" action="admin.php?view=product" method="post"  enctype="multipart/form-data" onsubmit="return ValidateForm();">
							<input type="hidden" name="view" value="product" />
							<table>
								<tr>
									<td>Name:</td><td>
									<input type="text" name="Name" id="Name" size=50 maxlength=200>
									</td>
								</tr>
								<tr>
									<td>Price:</td><td>
									<input type="text" name="Price" id="Price" size=50 maxlength=200>
									</td>
								</tr>
								<tr>
									<td>Quantity:</td><td>
									<input type="text" name="Quantity" id="Quantity" size=50 maxlength=200>
									</td>
								</tr>

								<tr>
									<td>Category:</td>
									<td>
									<input type="text" name="Category" id="Category" size=50 maxlength=200>
									</td>
								</tr>
								<tr>
									<td>Image</td>
									<td>
									<input type="file" name="ImageName" id="ImageName" size="32" style="width:335px" />
									</td>
								</tr>
								<tr>
									<td>Description:</td>
									<td><textarea id="Description" name="Description" cols="50" rows="5" style="width:335px"></textarea></td>
								</tr>

								<tr>
									<td>Available</td>
									<td>
									<input type="checkbox" name="Available" value="1" />
									</td>
								</tr>
								<tr>
									<td colspan="2" align="right">
									<input type="submit" value="Add" name="Submit"/>
									<input type="submit" value="Modify" name="Submit"/>
									<input type="reset" value="Reset" name="Clear">
									</td>

								</tr>
							</table>

						</form>
</div>
						<!-- end content -- -->
					</div>
				</div>

			</div>

		</div>

		<?
		include 'web/body.wrapper.phtml';
		?>
	</body>
</html>

